package com.ruoyi.cms.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.web.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.cms.mapper.CLogoMapper;
import com.ruoyi.cms.domain.CLogo;
import com.ruoyi.cms.service.ICLogoService;

/**
 * LOGO管理Service业务层处理
 * 
 * @author Choi
 * @date 2021-08-23
 */
@Service
public class CLogoServiceImpl implements ICLogoService 
{
    @Autowired
    private CLogoMapper cLogoMapper;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询LOGO管理
     * 
     * @param id LOGO管理ID
     * @return LOGO管理
     */
    @Override
    public CLogo selectCLogoById(Long id)
    {
        return cLogoMapper.selectCLogoById(id);
    }

    /**
     * 查询LOGO管理列表
     * 
     * @param cLogo LOGO管理
     * @return LOGO管理
     */
    @Override
    public List<CLogo> selectCLogoList(CLogo cLogo)
    {
        cLogo.setUserId(this.getUserId());
        return cLogoMapper.selectCLogoList(cLogo);
    }

    /**
     * 新增LOGO管理
     * 
     * @param cLogo LOGO管理
     * @return 结果
     */
    @Override
    public int insertCLogo(CLogo cLogo)
    {
        cLogo.setUserId(this.getUserId());
        cLogo.setCreateTime(DateUtils.getNowDate());
        return cLogoMapper.insertCLogo(cLogo);
    }

    /**
     * 修改LOGO管理
     * 
     * @param cLogo LOGO管理
     * @return 结果
     */
    @Override
    public int updateCLogo(CLogo cLogo)
    {
        cLogo.setUpdateTime(DateUtils.getNowDate());
        return cLogoMapper.updateCLogo(cLogo);
    }

    /**
     * 批量删除LOGO管理
     * 
     * @param ids 需要删除的LOGO管理ID
     * @return 结果
     */
    @Override
    public int deleteCLogoByIds(Long[] ids)
    {
        return cLogoMapper.deleteCLogoByIds(ids);
    }

    /**
     * 删除LOGO管理信息
     * 
     * @param id LOGO管理ID
     * @return 结果
     */
    @Override
    public int deleteCLogoById(Long id)
    {
        return cLogoMapper.deleteCLogoById(id);
    }

    private SysUser getUser() {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        if (loginUser == null) {
            return null;
        }
        SysUser user = loginUser.getUser();
        return user;
    }

    private Long getUserId() {
        SysUser user = this.getUser();
        return user == null ? 0 : user.getUserId();
    }
}
